//
//  ViewController.m
//  CAGradientLayerAnimation
//
//  Created by Xwoder on 17/2/1.
//  Copyright © 2017年 Xwoder. All rights reserved.
//

#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[(id)[UIColor blackColor].CGColor, (id)[UIColor whiteColor].CGColor, (id)[UIColor blackColor].CGColor];
    gradientLayer.locations = @[@(0), @(0.1), @(0.2)];
    gradientLayer.frame = self.view.bounds;
    gradientLayer.startPoint = CGPointZero;
    gradientLayer.endPoint = CGPointMake(0, 1);
    [self.view.layer addSublayer:gradientLayer];
    
    CABasicAnimation *animation = [CABasicAnimation animation];
    animation.keyPath = @"locations";
    animation.duration = 2;
    animation.toValue = @[@(0.8), @(0.9), @(1)];
    animation.autoreverses = YES;
    animation.repeatCount = HUGE_VALF;
    [gradientLayer addAnimation:animation forKey:nil];
}

@end
